package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.AccountBean;
import com.mz.ozy.bean.LogoutBean;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.UnreadMsgBean;
import com.mz.ozy.mvp.model.LogoutModel;
import com.mz.ozy.mvp.model.MeModel;
import com.mz.ozy.mvp.view.LogoutContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class LogoutPresenter extends BasePresenterImpl<LogoutContract.View> implements LogoutContract.Presenter {

    private LogoutModel mModel;


    public LogoutPresenter() {
        mModel = new LogoutModel();
    }

    @Override
    public void getCode(Context context,String phone) {
        mModel.getCode(context,phone)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getCodeSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void setLogout(Context context, String username, String code) {
        mModel.setLogout(context,username,code)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<LogoutBean>(mView) {
                    @Override
                    public void onSuccesss(LogoutBean bean) {
                        mView.setLogoutSuccess(bean);
                    }
                });
    }
    public void exitLogin(Context context) {
        mModel.exitLogin(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.exitLoginSuccess(bean);
                    }
                });
    }

}
